home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / cslib15b.zip / DEMO / PANEL / CSPANDEM.CPP next >
Text File  |  1994-12-20  |  14KB  |  373 lines

  1. #include "conio.h"
  2. #include "stdio.h"
  3. #include "cskeys.h"
  4. #include "cspanel.h"
  5.  
  6.  
  7. /***********************************************************************
  8.  
  9.                                        CSA Library, Release 1.5.b 
  10.  
  11.  
  12.                The CSA Library.
  13.            A demonstration of the PANEL class.
  14.  
  15.                                           Copyright(c) 1994 
  16.                                           Combis 
  17.                                           The Netherlands   
  18. ***********************************************************************/
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. void main(void)
  26. {
  27.  
  28.   desktop();
  29.  
  30. ////////////////////// Explanation ////////////////////////////////
  31.  
  32.   WINDOW w1;
  33.   w1.head(" Panel Demonstration Program ");
  34.   w1.activate();
  35.  
  36.   cprintf("\n\n\r ");
  37.   cprintf("\n\r                    This program will show you     ");
  38.   cprintf("\n\r                    three PANELS.                  ");
  39.   cprintf("\n\r                    The first one will be very     ");
  40.   cprintf("\n\r                    simple. It is intended to      ");
  41.   cprintf("\n\r                    demonstrate the defaults.      ");
  42.   cprintf("\n\r                                                   ");
  43.   cprintf("\n\r                    The second panel is an         ");
  44.   cprintf("\n\r                    elaborate one, using most of   ");
  45.   cprintf("\n\r                    the available options.         ");
  46.   cprintf("\n\r                                                   ");
  47.   cprintf("\n\r                    The third one shows the        ");
  48.   cprintf("\n\r                    automatic data validation,     ");
  49.   cprintf("\n\r                    applied to different data      ");
  50.   cprintf("\n\r                    types.                         ");
  51.   cprintf("\n\r                                                   ");
  52.   cprintf("\n\r                    Hit any key to continue.       ");
  53.  
  54.   cskey();
  55.  
  56.  
  57.   w1.clear();
  58.   cprintf("\n\r ");
  59.   cprintf("\n\r                           About data validation.      ");
  60.   cprintf("\n\r                                                       ");
  61.   cprintf("\n\r               The validation of the edited fields is done afterwards.   ");
  62.   cprintf("\n\r               This means you can enter almost anything, but you can only    ");
  63.   cprintf("\n\r               advance to the next field if the string satisfies the   ");
  64.   cprintf("\n\r               validation restrains.                   ");
  65.   cprintf("\n\r                                                       ");
  66.   cprintf("\n\r               strings:  No validation by default.     ");
  67.   cprintf("\n\r               integers: Maximal 5 digits and no       ");
  68.   cprintf("\n\r                         preceding zero's.             ");
  69.   cprintf("\n\r               longs:    Maximal 10 digits and no      ");
  70.   cprintf("\n\r                         preceding zero's.             ");
  71.   cprintf("\n\r               date:     Valid calendar date,          ");
  72.   cprintf("\n\r                         leap years are account for.   ");
  73.   cprintf("\n\r               float:                                  ");
  74.   cprintf("\n\r               double:   Valid floating point number,  ");
  75.   cprintf("\n\r                         meaningless preceding         ");
  76.   cprintf("\n\r                         zero's are not allowed.       ");
  77.   cprintf("\n\r                                                       ");
  78.   cprintf("\n\r                    Hit any key to continue.           ");
  79.  
  80.   cskey();
  81.  
  82.  
  83. /////////////////////// The Keys ////////////////////////////////////
  84.   w1.clear();
  85.   cprintf("\n\n\n\r                             A VERY simple panel. ");
  86.   cprintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\r");
  87.   cprintf("         EDIT KEYS: delete, backspace, cursor, insert, tab.   \n\r" );
  88.   cprintf("         EXIT:      enter or esc.               \n\r");
  89.   cprintf("\n                    All fields can be edited.     ");
  90.  
  91.  
  92. /////////////////////// Variables for the 1st panel ///////////////////
  93.  
  94.   char st[26]="The first field."; // Allocate for at least 25 characters
  95.   int i=25;
  96.   char c='Y';
  97.  
  98.  
  99. /////////////////////// Define the 1st panel //////////////////////////
  100.   PANEL pan1;              // Declare panel.
  101.  
  102.   pan1.height(9);          // Set the height
  103.   pan1.width(40);          // Set the width
  104.  
  105.   pan1.add_field(2,2,25,st);      // Add field at pos 2,2 with length 25
  106.   pan1.add_field(4,2,7,i);      // Add field at pos 4,2 with length 7
  107.   pan1.add_field(6,2,1,c);      // Add field at pos 6,2 with length 1
  108.  
  109. /////////////////////// Browse through it //////////////////////////////
  110.  
  111.   pan1.read();              // Display and edit
  112.  
  113.  
  114. /////////////////////// Show the code //////////////////////////////////
  115.   w1.activate();
  116.   w1.clear();
  117.  
  118.   WINDOW w2;
  119.   w2.set_dim(-1,-1,24,80);
  120.   w2.head(" This is all it took! ");
  121.   w2.activate();
  122.   cprintf("                                                                        \n\r");
  123.   cprintf(" char st[26]=\"The first field.\"; // Allocate for at least 25 characters \n\r");
  124.   cprintf(" int i=25;                                                              \n\r");
  125.   cprintf(" char c='Y';                                                            \n\r");
  126.   cprintf("                                                                        \n\r");
  127.   cprintf(" PANEL pan1;                     // Declare panel.                      \n\r");
  128.   cprintf("                                                                        \n\r");
  129.   cprintf(" pan1.height(9);                 // Set the height                      \n\r");
  130.   cprintf(" pan1.width(40);                 // Set the width                       \n\r");
  131.   cprintf("                                                                        \n\r");
  132.   cprintf(" pan1.add_field(2,2,25,st);      // Add field at pos 2,2 with length 25 \n\r");
  133.   cprintf(" pan1.add_field(4,2,7,i);        // Add field at pos 4,2 with length 7  \n\r");
  134.   cprintf(" pan1.add_field(6,2,1,c);        // Add field at pos 6,2 with length 1  \n\r");
  135.   cprintf("                                                                        \n\r");
  136.   cprintf(" pan1.read();                    // Display and edit                    \n\r");
  137.   cprintf("                                                                        \n\r");
  138.   cprintf("               // Notice the conversion from integer to string and      \n\r");
  139.   cprintf("               // vice versa is done automatically.                     \n\r");
  140.   cprintf("               // The syntax for adding a field is the same             \n\r");
  141.   cprintf("               // for every data type.                                    \n\r");
  142.   cprintf("                                                                        \n\r");
  143.   cprintf("    Hit any key to continue......                                       ");
  144.  
  145.  
  146.   cskey();
  147.  
  148.  
  149.  
  150.  
  151. /////////////////////// Complex Panel ///////////////////////////////
  152.  
  153.   cprintf("\n\n\r      A complicated panel. ");
  154.  
  155.  
  156.   w2.remove();
  157.   w2.set_dim(-1,-1,19,60);
  158.   w2.head(" Panel 2 ");
  159.   w2.activate();
  160.  
  161.   w2.clear();
  162.  
  163.   cprintf("\n\n\r");
  164.   cprintf("   In the next panel you can only 'exit' by pressing \n\r");
  165.   cprintf("   F10 while the cursor is in the 'exit' field.      \n\r");
  166.   cprintf("   The 'ESC' key has been disabled.                  \n\r");
  167.   cprintf("                                                     \n\r");
  168.   cprintf("   Strings which are longer then the                 \n\r");
  169.   cprintf("   field will SCROLL within the field.               \n\r");
  170.   cprintf("                                                     \n\r");
  171.   cprintf("   Two fields are 'browse only' which                \n\r");
  172.   cprintf("   means you are able to put the cursor              \n\r");
  173.   cprintf("   at the field, but are not allowed to edit.        \n\r");
  174.   cprintf("   One field is 'display only', because of           \n\r");
  175.   cprintf("   that the cursor will skip it.                     \n\r");
  176.   cprintf("                                                     \n\r");
  177.   cprintf("                Hit any key to continue. ");
  178.  
  179.   cskey();
  180.   w2.remove();
  181.  
  182.  
  183. /////////////////////// Variables for the panel ///////////////////
  184.  
  185.   char name[]="Neil A. Armstrong ";
  186.   char ship[]="USS Enterprise  ";
  187.   char rank[]="Retired ";
  188.   char acco[]="The first man ever to set foot on the moon. ";
  189.   char info[]="Neil Armstrong was an astronaut in the years 1962-1970.";
  190.   char birth[]="22/03/1930";
  191.   char ok[]="You can leave the panel by pressing F10 in this field.";
  192.  
  193.  
  194. ///////////////////////// PANEL DEFINITION /////////////////////
  195.   PANEL panel;
  196.  
  197.   panel.set_dim(4,11,17,65);               // Size and Position of panel
  198.   panel.head(" Panel 2 ");                     // Heading
  199.   panel.border(BORDER_DOUBLE);               // Type of border
  200.   panel.activate();                   // Make panel-window visible
  201.  
  202.   gotoyx(2,10); cprintf("Astronaut: ");
  203.   panel.add_field(3,10,25,name);
  204.  
  205.   gotoyx(5,10); cprintf("Favourite space ship: ");
  206.   panel.add_field(6,10,25,ship);
  207.   panel.protect(DISPLAY);               // Display only (no editting).
  208.  
  209.   gotoyx(2,40); cprintf("Rank: ");
  210.   panel.add_field(3,40,15,rank);
  211.  
  212.   gotoyx(5,40); cprintf("Birthday (DD/MM/YYYY): ");
  213.   panel.add_field(6,40,birth);
  214.  
  215.   gotoyx(8,10); cprintf("Accomplishment: ");
  216.   panel.add_field(9,10,30,acco);
  217.   panel.mod_field.max_len(60);               // Max. 60 pos. for the string
  218.  
  219.   gotoyx(10,10); cprintf("Additional info: ");
  220.   panel.add_field(11,10,25,info);
  221.   panel.protect(BROWSE);
  222.  
  223.   panel.add_field(15,4,strlen(ok)+2,ok);
  224.   panel.mod_field.border(BORDER_SINGLE);       // A field with a border!
  225.   panel.mod_field.head("Exit");
  226.   panel.mod_field.border_color(panel.screen_color());
  227.   panel.protect(BROWSE);
  228.   panel.exit_field(TRUE);
  229.  
  230.   panel.exit_key(F10);
  231.  
  232.   panel.escape_off();
  233.  
  234.  
  235. /////////////////////// Browse through it //////////////////////////////
  236.  
  237.   panel.read();
  238.  
  239. /////////////////////// Removing panel /////////////////////////////////
  240.  
  241.   panel.remove();
  242.  
  243. /////////////////////// Do some explaining //////////////////////////
  244.   w1.clear();
  245.  
  246.  
  247.   w2.remove();
  248.   w2.head(" Data validation example ");
  249.   w2.set_dim(3,-1,20,60);
  250.   w2.activate();
  251.  
  252.   w2.clear();
  253.  
  254.   cprintf("\n\r");
  255.   cprintf("   The last panel gives an impression          \n\r");
  256.   cprintf("   of the capabilities concerning              \n\r");
  257.   cprintf("   data validation.                            \n\r");
  258.   cprintf("                                               \n\r");
  259.   cprintf("   For each supported type is a                \n\r");
  260.   cprintf("   field present.                              \n\r");
  261.   cprintf("                                               \n\r");
  262.   cprintf("   You can't leave a field until               \n\r");
  263.   cprintf("   the edited string is considered             \n\r");
  264.   cprintf("   to be valid.                                \n\r");
  265.   cprintf("                                               \n\r");
  266.   cprintf("   Leave the panel by pressing 'F10' or 'ESC'. \n\r");
  267.   cprintf("   'ESC' will exit the panel immediately,      \n\r");
  268.   cprintf("   even with invalid fields.                   \n\r");
  269.   cprintf("   See for yourself!                           \n\r");
  270.   cprintf("                                               \n\r");
  271.   cprintf("                Hit any key to continue. ");
  272.   cskey();
  273.   w2.remove();
  274.   w1.clear();
  275.  
  276.  
  277. /////////////////////// Variables for the panel ///////////////////
  278.  
  279.   char str[]="Some string.";
  280.   char ch='c';
  281.   int  in=123;
  282.   long lo=1234567890;
  283.   float fl=3.14159265358;
  284.   double df=1.1;
  285.   DATE date="22/03/1930";
  286.  
  287.  
  288.  
  289. ///////////////////////// PANEL DEFINITION /////////////////////
  290.  
  291.  
  292.   panel.set_dim(-1,-1,21,75);
  293.   panel.head(" Data Validation  ");
  294.   panel.border(BORDER_DOUBLE);
  295.   panel.activate();
  296.  
  297.   gotoyx(1,40); cprintf(" Min        Max        Picture");
  298.   gotoyx(2,40); cprintf("                     String");
  299.   gotoyx(3,40); cprintf("                             ");
  300.  
  301.   gotoyx(4,10); cprintf("String: ");
  302.   panel.add_field(4,20,15,str);
  303.   panel.mod_field.set_max("zyx");
  304.   panel.mod_field.set_min("Aaa");
  305.   gotoyx(4,40); cprintf("'AAA' < X < 'zyx'");
  306.  
  307.  
  308.  
  309.   gotoyx(6,10); cprintf("Character: ");
  310.   panel.add_field(6,20,1,ch);
  311.   panel.mod_field.set_max('z');
  312.   panel.mod_field.set_min('a');
  313.   gotoyx(6,40); cprintf("  'a' < X < 'z'");
  314.  
  315.  
  316.   gotoyx(8,10); cprintf("Integer: ");
  317.   panel.add_field(8,20,9,in);
  318.   panel.mod_field.picture("ooo");
  319.   panel.mod_field.set_max(399);
  320.   panel.mod_field.set_min(100);
  321.   gotoyx(8,40); cprintf("  100 < X < 399          ooo");
  322.  
  323.  
  324.  
  325.   gotoyx(10,10); cprintf("Long: ");
  326.   panel.add_field(10,20,18,lo);
  327.   panel.mod_field.set_min(10L);
  328.   gotoyx(10,40); cprintf("   10 < X");
  329.  
  330.  
  331.  
  332.   gotoyx(12,10); cprintf("Float: ");
  333.   panel.add_field(12,20,15,fl);
  334.   panel.mod_field.set_max(9e10);
  335.   panel.mod_field.set_min(1e-10);
  336.   gotoyx(12,40); cprintf("1e-10 < X < 9e10");
  337.  
  338.  
  339.  
  340.   gotoyx(14,10); cprintf("Double: ");
  341.   panel.add_field(14,20,25,df);
  342.   panel.mod_field.set_max(1e6);
  343.   panel.mod_field.picture("o.oo[0|e|E]o");
  344.   gotoyx(14,40); cprintf("        X < 1e6     o.oo[0|e|E]o");
  345.  
  346.  
  347.   gotoyx(16,10); cprintf("Date: ");
  348.   panel.add_field(16,20,date);
  349.  
  350.   DATE dm="31/12/1999";
  351.   DATE di="01/01/1900";
  352.   panel.mod_field.set_max(dm);
  353.   panel.mod_field.set_min(di);
  354.   gotoyx(16,35); cprintf("01/01/1900 < X < 31/12/1999" );
  355.   gotoyx(19,25); cprintf("Exit with ESC or F10");
  356.  
  357.  
  358.   panel.exit_key(F10);
  359.  
  360.  
  361. /////////////////////// Browse through it //////////////////////////////
  362.  
  363.   panel.read();
  364.  
  365. /////////////////////// removing panel /////////////////////////////////
  366.  
  367.  
  368.   panel.remove();
  369.   pan1.remove();
  370.  
  371.  
  372. }
  373.